﻿using System;
using System.Windows.Forms;
using AccessControl.Business;
using DevExpress.XtraEditors;

namespace AccessControl.SecurityMonitoring.Form
{
    public partial class PersonSelector : XtraForm
    {

        #region Fields


        #endregion

        #region Constructor

        public PersonSelector()
        {
            InitializeComponent();
        }

        #endregion

        #region Method

        private void GetData(){
            Common.AccessControlDS.tblPersonDataTable personDataTable=null;
            try{
                personDataTable = (Common.AccessControlDS.tblPersonDataTable) PersonBusiness.SelectAllWithoutPhoto();
                if (personDataTable != null)
                    accessControlDS.tblPerson.Merge(personDataTable);
                accessControlDS.AcceptChanges();
            }
            catch (Exception ex){

                //MessageBox.Show(ex.Message + "," + personDataTable.Rows.Count);
            }

        }

      #endregion

        #region Properties

        private Boolean IsSelected
        {
            get
            {
                return gridViewCon.SelectedRowsCount > 0;
            }
        }

        public AccessControlDS.tblPersonRow SelectedPersonRow
        {
            get
            {
                return
                    ((AccessControlDS.tblPersonRow) gridViewCon.GetDataRow(gridViewCon.GetSelectedRows()[0]));
            }
        }

        #endregion

        #region Event Handler

        private void simpleButtonOK_Click(object sender, EventArgs e)
        {
            if (IsSelected)
                simpleButtonOK.DialogResult = DialogResult.OK;
        }

        private void WorkflowSelector_Load(object sender, EventArgs e)
        {
            GetData();
        }

        private void WorkflowSelector_KeyDown(object sender, KeyEventArgs e)
        {
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    if (IsSelected)
                        simpleButtonOK.PerformClick();
                    break;

                case Keys.Escape:
                    if (IsSelected)
                        simpleButtonCancel.PerformClick();
                    break;
            }
        }

        private void gridViewWorkflow_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            if (IsSelected && (e.Clicks == 2))
                simpleButtonOK.PerformClick();
        }

        #endregion

    }
}